package com.securitytrace.client.util;

import java.io.FileInputStream;
import java.net.URL;
import java.util.Properties;


public class PropertiesUtil {

	static FileInputStream fi = null;

	/**
	 * 
	 * @param fileName
	 * @return Properties
	 */
	public static Properties getProperties(String fileName) {
		URL url = getPropertiesURL(fileName);
		return getPropertiesByURL(url);
	}

	/**
	 * 
	 * @param fileName
	 * @return URL
	 */
	public static URL getPropertiesURL(String fileName) {
		try {
			URL url = null;
			url = PropertiesUtil.class.getResource("/" + fileName);
//			String s = url.toString();
//			if (s.indexOf("file:\\") != -1) {
//				int indexOf = s.indexOf("file://") + 6;
//				String temp = s.substring(0, indexOf);
//				url = new URL(temp + "//" + s.substring(indexOf));
//			}
			return url;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	/**
	 * 
	 * @param url
	 * @return Properties
	 */
	public static Properties getPropertiesByURL(URL url) {
		try {
			Properties props = new Properties();
			props.load(url.openStream());
			return props;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
}
